
var gn = document.getElementsByName('gn')[0];
var kg =  document.getElementsByClassName('pm-kg')[0];

console.log('gn',gn);
console.log('gnValue',gn.value);
console.log('gnValue',typeof(gn.value));

if (gn.value) {
	var gnArr = gn.value.split(',');
} else {
	var gnArr = new Array();
}

for (var i = 0; i < gnArr.length; i++) {
	var lsn = document.getElementsByClassName(gnArr[i])[0];

	console.log('lsn ' + lsn + ' enen');
	if (lsn != undefined) {
		console.log('不是未定义才执行');
		console.log(lsn.classList);
		lsn.classList.add('seleted');
	}; 
};

kg.onclick = function(ev) {

	console.log(ev.target.classList);
	console.log(typeof(ev.target.classList));

	
	var smg = ev.target.classList;
	var sgn = ev.target.dataset.gn;
	if (smg.value.indexOf('seleted') != '-1') {
		smg.remove('seleted');
		if(gnArr.indexOf(sgn) != '-1'){
			if (sgn != undefined) {
				console.log('找到了');
				var wz = gnArr.indexOf(sgn);
				if (wz != '-1') {
					gnArr.splice(wz,1)
				};
				gn.value = gnArr;
			};
		}
		console.log(gnArr);
	} else {
		if (sgn != undefined) {
			smg.add('seleted');
			if(gnArr.indexOf(sgn) == '-1'){
				console.log('没找到');
				gnArr.push(sgn);
				gn.value = gnArr;
			}
			console.log(gnArr);
		}	
	}

}

